<!--
 * @Description: 布绑列表
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-05-12 16:25:40
 * @FilePath: /yuxiuproweb/src/views/mes/pro/workorder/mods/room/straps/index.vue
-->
<template>
  <el-dialog
    :close-on-click-modal="false"
    v-dialogDrag
    title="布绑列表"
    :visible.sync="shows"
    width="800px"
    append-to-body
  >
    <el-row :gutter="10" class="mb8" v-if="!strapsList.length">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['md:order:add']"
          >新增</el-button
        >
      </el-col>
    </el-row>

    <el-table :data="strapsList">
      <el-table-column label="品名" align="center" prop="name" />
      <el-table-column label="相关信息" align="center" prop="info">
      </el-table-column>
      <el-table-column label="价格" align="center" prop="price">
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="130"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['md:order:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['md:order:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="shows = false">关 闭</el-button>
    </div>

    <!-- 添加 -->
    <add-view
      v-if="add.show"
      :show.sync="add.show"
      v-bind="add"
      @update="getList"
    ></add-view>
  </el-dialog>
</template>

<script>
import { listStraps, delStraps, getStraps } from "@/api/asc/straps";
import AddView from "./add.vue";
export default {
  components: {
    AddView,
  },
  props: {
    show: Boolean,
    type: {
      type: String,
      default: "add",
    },
    data: {
      type: Object,
    },
  },
  data() {
    return {
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
      },
      add: {
        show: false,
        type: "add",
        data: null,
      },
      strapsList: [],
    };
  },
  computed: {
    shows: {
      get() {
        return this.show;
      },
      set(newValue) {
        this.$emit("update:show", newValue);
        if (!newValue) {
          this.$emit("update");
        }
      },
    },
  },
  created() {
    console.log(this.data);
    this.getList();
  },
  methods: {
    getList() {
      listStraps({
        ...this.queryParams,
        orderCustomCurtainId: this.data.proOrderCustomCurtainId,
      }).then(({ rows, total }) => {
        this.strapsList = rows;
        this.total = total;
      });
    },
    handleAdd() {
      this.add = {
        show: true,
        type: "add",
        data: {
          proOrderCustomCurtainId: this.data.proOrderCustomCurtainId,
        },
        curtain: {
          ...this.data,
        },
      };
    },
    handleUpdate(row) {
      this.add = {
        show: true,
        type: "edit",
        data: {
          ...row,
          proOrderCustomCurtainId: this.data.proOrderCustomCurtainId,
        },
        curtain: {
          ...this.data,
        },
      };
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderCustomCurtainStrapsIds = row.orderCustomCurtainStrapsId;
      this.$modal
        .confirm("是否确认删除布绑")
        .then(function () {
          return delStraps(orderCustomCurtainStrapsIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
